use rocket::http::{Method};
use rocket_cors::{Cors, AllowedOrigins, AllowedHeaders};

/// cors config
/// ### Usage:
/// ```ignore
/// rocket::ignite()
///         .attach(get_cors())
///         .launch()
/// ```
pub fn get_cors() -> Cors {
    let allowed_origins = AllowedOrigins::All;
    // You can also deserialize this
    rocket_cors::CorsOptions {
        allowed_origins,
        allowed_methods: vec![Method::Get, Method::Post, Method::Options].into_iter().map(From::from).collect(),
        allowed_headers: AllowedHeaders::All,
        allow_credentials: true,
        ..Default::default()
    }.to_cors().expect("cors config error")
}
